Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

5.6 Booting the Linux Kernel

The actual launch of the Linux kernel is orchestrated by commands such as bootm, bootd, bootefi, bootelf, bootz, bootvx, bootp, nfs, rarpboot, and tftpboot. Among these, bootm is used to boot application images from memory, bootd handles the default boot sequence, bootefi boots EFI-format image applications from memory, bootelf boots ELF-format image applications from memory, bootz boots images formatted as a zImage, and bootvx boots the VxWorks operating system, while the remaining commands are dedicated to booting Linux via network pathways. As seen in the bootcmd script, before the bootm command executes, U-BOOT first loads the Flattened Device Tree (DTB) blob and the secure TEE firmware file into memory. The following sections evaluate the process of U-BOOT booting Linux from an SD card, using the bootm command as a primary reference model.

For U-BOOT to successfully boot the Linux kernel, it must understand the specific storage and packaging format of the kernel on the storage medium. Prior to analyzing the execution path of the do_bootm function, the underlying kernel image file formats supported by Linux are detailed below.

5.6.1 Linux Image File Formats

When discussing Linux kernel formats, terms such as vmlinux, vmlinuz, zImage, bzImage, uImage, and FIT are frequently encountered. The vmlinux format is a statically linked executable ELF file of the kernel; it is a raw binary payload that can be loaded into memory and run directly, predominantly utilized for kernel troubleshooting and debugging. The vmlinuz format is a compressed version of vmlinux, which becomes runnable immediately upon decompression. U-BOOT does not directly consume raw vmlinux or standard desktop vmlinuz files.

The zImage and uImage formats represent the legacy image infrastructure, which remains heavily deployed in embedded U-BOOT pipelines. A zImage is a self-decompressing kernel container enclosing a specific magic number header, a lightweight decompression wrapper routine, and the compressed raw vmlinux payload. The binary structural layout of a standard zImage file is organized as follows:

Figure 5-13 zImage File Format

Within this topology, the executable code block (code) occupies the first 36 bytes of memory, followed immediately by a 4-byte Magic Number used by boot loaders to validate the payload as a definitive zImage. For the ARM Linux architecture, this magic signature is fixed to 0x016F2818. The zi_start marker denotes the absolute beginning address of the nested zImage executable logic, and zi_end points to its absolute termination boundary.

1. Single-Image uImage File Format

A uImage file is generated by wrapping a standard zImage container with a specialized U-BOOT header using the companion mkimage host utility. The uImage acts as an entry-ready kernel file that U-BOOT can parse and execute directly from memory. Its structural binary layout is structured as follows:

Figure 5-14 uImage File Format

The 64-byte structural file header encapsulates the magic number, file header CRC checksum, file creation timestamp, image payload size, destination memory load address, application execution entry point, data (the inner zImage) CRC checksum, target operating system identifier, target CPU architecture token, image wrapper type, compression method flag, and the image name string.

  • Magic Number: A constant signature fixed to 0x27051956, which software routines evaluate to distinguish a legacy uImage file container from modern flattened image trees (FIT).

  • Header CRC Checksum: A Cyclic Redundancy Check validation word protecting the integrity of the 64-byte header block.

  • Creation Time: A standard Unix epoch timestamp registering the exact moment the image file was packed.

  • Image Size: Encodes the exact linear volume of the embedded zImage payload in bytes.

  • Load Address: Defines the baseline physical target address in RAM where the kernel payload must be uncompressed and relocated.

  • Entry Point: Explicitly marks the absolute address of the first machine instruction executed to initiate the kernel boot.

  • Data CRC Checksum: A Cyclic Redundancy Check validation word protecting the integrity of the inner zImage binary payload.

  • Operating System ID: An architecture token identifying the target operating system environment, such as Linux, VxWorks, NetBSD, or FreeBSD. Contemporary versions of U-BOOT provide native support for 28 distinct operating systems and firmware targets.

  • CPU Type: An architecture token mapping the compiled payload to its designated silicon target. U-BOOT currently identifies 26 discrete processor configurations including ARM, PowerPC (PPC), and x86 architectures.

  • Image Type: Maps the payload to one of 40 functional software categories, including standalone, kernel, firmware, tee, script, ramdisk, or multi.

  • Compression Type: Registers the algorithm utilized to compress the underlying zImage, with native support covering uncompressed raw blocks, gzip, bzip2, lzma, lzo, and lz4 compression variants.

  • Image Name: A descriptive text string identifying the image, capped at a maximum length of 32 characters including the null terminator.

2. Multi-Image uImage File Format

When the embedded image type field is initialized to configuration value 05 (multi), the legacy uImage container is refactored to wrap multiple independent sub-images within a single contiguous file block. The multi-image payload architecture presented in the diagram below encapsulates a compiled kernel binary, a compressed root RAMDISK container, and the platform Device Tree Blob (DTB) payload:

Figure 5-15 Multi-Image Program File Structure

3. Flattened Image Tree (FIT) Image Structure

FIT is an acronym for Flattened Image Tree. Sharing the identical architectural design as the standard Device Tree, a FIT program image file is generated from a hierarchical, tree-structured source document describing the component images. This tree-structured file is authored using the same text-based language syntax as the Device Tree, where configuration blocks within the tree define how each component of the consolidated image file should be utilized. The file describing this image tree structure uses the .its extension suffix and strictly opens with the /dts-v1/; token declaration.

The hierarchical tree topology is composed of structured nodes, anchored at the top by a mandatory root node represented as a forward slash (/). The root node encapsulates individual image descriptors (images) and configuration sets (configurations), alongside the global description and #address-cells properties. The description property supplies a text summary explaining the image container, while #address-cells specifies the exact number of 32-bit cells required to encode node addresses within this context. U-BOOT parses these node addresses to cross-access and extract nested content from the flattened image blob. Both the images container and the configurations container can host multiple distinct child nodes, which are accessed via their defined addresses or unit tags.

The individual child nodes nested inside the images block can encapsulate legacy uImage files, compiled Flattened Device Tree blobs (.dtb), or compressed RAM disk images. Each independent child node block supports the description, data, type, arch, os, compression, load, entry, and hash attributes:

  • description: A descriptive text summary identifying the specific sub-image component.

  • data: Specifies the source binary payload to include, typically injected using the raw binary inclusion operator (/incbin/).

  • type: Registers the functional category of the binary payload (e.g., kernel, flat_dt, ramdisk).

  • arch: Identifies the target instruction set architecture compatible with the payload (e.g., arm, x86, riscv).

  • os: Specifies the guest operating system type to initialize.

  • compression: Registers the compression algorithm used to compress the target binary sequence.

  • load: Defines the absolute target address in physical RAM where the binary payload must be unpacked or copied.

  • entry: Specifies the absolute memory execution vector where control is transferred to start the program.

  • hash: Dictates the integrity verification algorithm applied to validate the sub-image segment.

The configurations container block can host multiple child configuration nodes alongside a top-level default selection attribute to define how the different compiled image pieces are joined together at runtime. For example, in the reference schema provided below, the default selection pointer targets config@1. The configuration matrix under config@1 specifies that the system must boot using the primary kernel defined under the kernel@1 node paired with the Flattened Device Tree blob registered under the fdt@1 node:

/dts-v1/;
/ {
	description = "Marcus FIT test";
	#address-cells = <1>;
	images {
		kernel@1 {
			description = "My default kernel";
			data = /incbin/("./zImage");
			type = "kernel";
			arch = "arm";
			os = "linux";
			compression = "none";
			load = <0x83800000>;
			entry = <0x83800000>;
			hash@1 {
				algo = "md5";
			};
		};
		kernel@2 {
			description = "Rescue image";
			data = /incbin/("./zImage");
			type = "kernel";
			arch = "arm";
			os = "linux";
			compression = "none";
			load = <0x83800000>;
			entry = <0x83800000>;
			hash@1 {
				algo = "crc32";
			};
		};
		fdt@1 {
			description = "FDT for my cool board";
			data = /incbin/("./devicetree.dtb");
			type = "flat_dt";
			arch = "arm";
			compression = "none";
			hash@1 {
				algo = "crc32";
			};
		};
	};
	configurations {
		default = "config@1";
		config@1 {
			description = "Default configuration";
			kernel = "kernel@1";
			fdt = "fdt@1";
		};
		config@2 {
			description = "Rescue configuration";
			kernel = "kernel@2";
			fdt = "fdt@1";
		};
	};
};

The root node can contain images and configurations child nodes. Within contemporary U-BOOT trees, the properties currently supported under the images child nodes encompass data, data-position, data-offset, data-size, timestamp, description, arch, type, os, compression, entry, and load. The data property is predominantly utilized to establish the location or reference path of the program code or source binary block. Concurrently, a node under the configurations block supports properties such as kernel, ramdisk, fdt, loadable, default, setup, fpga, firmware, and standalone.

Furthermore, the FIT specification supports secure cryptographic verification layers through dedicated signature and key verification nodes, including hash, signature, and key. A key configuration node can host attributes such as hash, algo, value, u-boot-ignore, signature, required, and key-name-hint. A cipher block node accommodates the cipher data pointer and its accompanying algo selection. These cipher and hash nodes are nested as child nodes within individual images components to enforce hardware-level image authenticity checks and implement encrypted high-assurance secure boots.

U-BOOT cannot directly parse or execute a raw text-based .its file. The file must first be flattened into a single operational binary image tree blob suffixed with the .itb extension using the host mkimage compilation utility. The schematic diagram below illustrates the exact input components and compiled output artifact managed during this mkimage build step:

Figure 5-16 Generation Process of the ITB File

The diagram below shows the core structural design and header alignment of the final compiled .itb binary image payload. Mirroring the binary layout rules of standard flattened device trees, the hierarchical image tree topology uses nesting definitions to append child node name strings directly beneath their corresponding parent block structures. Properties declared within these child nodes point to specific string tokens and tracking lengths packed into a centralized strings block database; the parsing engine traverses this string block via numerical offsets to read property values. FIT leverages this layout to encapsulate multi-component execution trees cleanly. For granular formatting guidelines and syntactical specifications, developers can consult the official Devicetree Specification documentation.

Figure 5-17 FIT File Structure

5.6.2 Booting the Linux Kernel via the bootm Command

Following the analysis of the binary image structures, this section evaluates the technical workflow under which U-BOOT leverages the do_bootm function to boot the Linux kernel.

The do_bootm function initially parses the command line string to verify if specific bootm sub-commands are declared. If sub-commands are detected, U-BOOT processes them sequentially to advance the bootstrap sequence. A sub-command executes only a partial or fractional slice of the complete bootm pipeline rather than a monolithic full boot. The tracking framework registers exactly eight sub-commands: start, loados, ramdisk, fdt, cmdline, bdt, prep, and go. If multiple sub-commands are issued manually by an operator, they must strictly follow this listed order, although executing the entire set is not structurally mandatory.

The universal syntax for the bootm utility is structured as follows:

bootm [addr [arg1 [arg2]]]

Where addr specifies the location in memory hosting the primary kernel image (typically a uImage or FIT blob base address), arg1 defines the physical memory address of the initialization RAM disk (initrd), and arg2 targets the compiled Flattened Device Tree (fdt) blob. If the target operating system configuration bypasses the use of a RAM disk, a hyphen placeholder (-) must be explicitly passed in place of arg1. As parsed within the bootcmd script analyzed in preceding chapters, the typical runtime execution syntax is expressed as:

bootm ${tee_addr} - ${fdt_addr}

Expanding this environment variable string (e.g., executing bootm 0x20000000 - 0x18000000) instructs the bootloader to branch execution into the program image hosted at address 0x20000000 without packing an initrd payload, while mapping the active Device Tree structure from base offset 0x18000000.

If no explicit sub-commands accompany the bootm invocation, the state machine must execute a complete, monolithic boot pipeline from scratch. Upon completing early sub-command checks, if the platform configuration has enabled High Assurance Boot (CONFIG_HAB), the routine triggers validation loops to authenticate the cryptographic signature and integrity of the outer uImage envelope. Concurrently, if the build incorporates support for OP-TEE secure layers, secondary hooks execute to validate the underlying zImage integrity.

Finally, the engine routes execution into do_bootm_states(), which acts as a centralized coordinator to step through the core initialization states sequentially: BOOTM_STATE_START, BOOTM_STATE_FINDOS, BOOTM_STATE_FINDOTHER, BOOTM_STATE_LOADOS, BOOTM_STATE_OS_PREP, BOOTM_STATE_OS_FAKE_GO, and BOOTM_STATE_OS_GO.

If a RAM-disk-based filesystem is deployed, the system branches into BOOTM_STATE_RAMDISK right after the OS loading phase concludes. Furthermore, if the processing architecture targets legacy PowerPC or MIPS silicon, the state machine must step through the OS_CMDLINE sub-state to construct command line strings. For an NXP i.MX6 application processor running mainline Linux, the definitive operational block array requires processing BOOTM_STATE_START, BOOTM_STATE_FINDOS, BOOTM_STATE_FINDOTHER, and BOOTM_STATE_LOADOS. Each discrete sub-state maps directly to a localized helper routine. The final sequence tiers—encompassing BOOTM_STATE_OS_PREP, BOOTM_STATE_OS_FAKE_GO, and BOOTM_STATE_OS_GO—are inherently OS-dependent; their final low-level executions are managed dynamically by invoking the targeted function pointers resolved via boot_fn() and boot_selected_os().

The continuous runtime execution flow tracking the do_bootm() function is mapped out in the schematic flowchart below:

Figure 5-18 do_bootm() Function Flowchart

The technical implementations and internal objectives of each core module within this flowchart are detailed below:

1. uImage Authenticity Verification

For the i.MX6 Solo/DualLite processors, U-BOOT handles cryptographic verification and decryption by interfacing directly with the hardware Cryptographic Acceleration and Assurance Module (CAAM) hosted inside the on-chip High Assurance Boot (HAB) silicon block. This hardware engine parses the binary Command Sequence File (CSF) tables embedded within the image's IVT wrapper to validate the uImage payload block. The physical base coordinates where the target uImage is evaluated align with the memory reference value configured inside the ${tee_addr} environment variable.

2. zImage Parameter Configuration

The bootloader inspects the internal text headers of the raw compressed kernel payload to extract the explicit zImage boundary vectors, registering its absolute starting and terminating memory coordinates. The baseline memory alignment tracking this zImage structure header is determined by the physical address value assigned to the standard U-BOOT ${loadaddr} environment variable.

3. zImage Authenticity Verification

U-BOOT leverages the on-chip HAB validation infrastructure and the CAAM engine to evaluate the CSF signatures tracking the zImage container, executing hardware-enforced image decryption and decryption verification passes. It must be noted that this specific ROM-driven pipeline handles authentication strictly for legacy single-image or multi-image binary wrappers; modern FIT container structures bypass this pathway, utilizing integrated self-contained cryptographic nodes to declare and enforce their own verification algorithms.

4. Sub-state Orchestration via do_bootm_states

The centralized coordinator steps through the following technical operations sequentially:

  • Initialization: Zeroes out all structural members of the internal bootm_headers_t tracking layout. If the platform build parameters have toggled the Logical Memory Block (CONFIG_LMB) macro constraint to fence off the lower bounds of memory accessible to the guest Linux kernel, the routine allocates and provisions the necessary lmb memory reservation tables at this stage.

  • Kernel Image Discovery: Initiates a lookup routine inside the loaded image block to isolate and parse the primary operating system kernel payload. The linear structural pipeline governing this component discovery path is illustrated below:

Figure 5-19 bootm_find_os() Function Flowchart

- Secondary Image Discovery: Searches the image fields to resolve and map external initialization components, including detached root RAM disks (ramdisk), Flattened Device Tree blobs (fdt), or generic secondary loadable payloads. The flowchart below charts the lookup execution pipeline targeting a ramdisk component when the boot loader is configured to parse modern FIT container layouts. (When operating over legacy single- or multi-image configurations, this discovery loop is significantly more linear). Furthermore, if the platform enables raw initial RAM disk support (raw initrd), developers can explicitly pass the target initrd execution address vectors directly via the bootm command string using colon separator delimiters. The initrd represents a transient baseline file system structure initially staged in RAM by the bootloader to provide the early user-space mounting environment during the Linux initialization phase.

Figure 5-20 bootm_find_other() Function

Flowchart
  • Operating System Payload Loading: Unpacks and relocates the compiled kernel binary payload contained inside the uImage wrapper. This data decompression and relocation pipeline follows the workflow detailed below:

Figure 5-21 bootm_load_os() Function Flowchart

  • Boot Handler Binding: Evaluates the explicit target operating system index stored within the os metadata field of the uImage header block. It invokes bootm_os_get_boot_func() to index into the generic boot_os[] function pointer array, dynamically binding the appropriate OS-specific bootstrap function handler. If the parsed os field matches configuration constant IH_OS_U_BOOT, the function pointer maps directly to the do_bootm_standalone() routine. In systems that execute bare-metal applications or dedicated firmware payloads without launching a complex multi-tasking operating system kernel, setting the target image profile to IH_OS_U_BOOT allows U-BOOT to unpack the standalone software directly into memory and hand over execution. The operational sequence tracking this standalone pathway is mapped out below:

Figure 5-22 do_bootm_standalone() Function Flowchart

Conversely, when the os header token evaluates to configuration index IH_OS_LINUX, verifying that the payload data segment encapsulates a valid Linux operating system kernel, the bound function pointer resolves directly to the do_bootm_linux() routine. At the final execution boundary, do_bootm_states() calls the top-level handler boot_selected_os(), which fires the resolved pointer to route execution straight into the Linux bootstrap sequence. For all standard Linux targets, this metadata flag must be explicitly configured to IH_OS_LINUX.

The low-level execution pipeline tracking the do_bootm_linux() bootstrap routine is structured as follows:

Figure 5-23 do_bootm_linux() Function Flowchart

Varying the integer constant inside the os header field alters the targeted operating system boot pathway and initialization logic accordingly. Upon concluding its low-level hardware alignment, parameter table packaging, and device tree mapping tasks, the do_bootm_linux() routine issues an unconditional branch instruction jumping directly into the absolute entry point execution vector (entry) defined by the kernel image. At this exact instruction cycle, U-BOOT terminates its operational life cycle, relinquishing absolute system control over to the newly active Linux kernel.

5.6.3 SPL Booting

The preceding sections evaluated the standard (Proper) execution pathway of U-BOOT. However, when the physical capacity of the CPU's on-chip SRAM is heavily constrained, the system can be configured to execute an SPL-based multi-stage boot sequence instead. In this topology, the hardcoded on-chip boot ROM first copies the lightweight SPL binary from storage into internal SRAM. Once active, the SPL initializes critical low-level infrastructure, brings up the clock trees, and configures the external DRAM controller. After volatile memory becomes fully accessible, the SPL reads the high-capacity U-BOOT Proper binary image from the storage medium into physical RAM, subsequently handing over execution so that U-BOOT Proper can drive the definitive operating system launch. As charted in Figure 5-3, both the SPL boot sequence and the standard U-BOOT Proper sequence ultimately transition into a post-relocation C entry function named board_init_r(). It must be explicitly noted that although both execution models invoke a function sharing the identical literal identifier, their internal programmatic structures and compilation outputs differ completely; the specialized board_init_r() handler processed during the SPL phase is defined explicitly within the source file git/common/spl/spl.c. When the platform build configuration toggles the macro switches to generate an SPL image, the linker cleanly couples this spl.c entry target. The fundamental responsibilities of this handler are to execute localized hardware initializations, parse the storage controllers to resolve the SPL boot list, and execute the final-stage bootloader binary. Its operational runtime pipeline is organized as illustrated in the schematic flowchart below:

Figure 5-24 SPL-Driven Bootloader Execution Flowchart

The programmatic operations and technical objectives of each core section within this flowchart are analyzed in detail below:

The board_init_r() function initially invokes a clear routine to zero out the spl_boot_list array structure. This tracking array functions as a prioritized linear repository storing the entry vectors and driver addresses of all valid, registered boot storage devices available on the hardware platform. The system then enters the spl_set_bd() helper block, which resolves the physical memory location allocated to store the baseline board parameters (board_info tables), an address boundary typically calculated and hardcoded at compile time by the linker script.

If the active build parameters have enabled the CONFIG_SYS_SPL_MALLOC_START preprocessor switch, the system calls mem_malloc_init() to carve out and provision the explicit memory space boundaries required to drive the dynamic heap allocator (malloc()) engine during the SPL phase. Upon doing so, it sets the GD_FLG_FULL_MALLOC_INIT flag bit inside the gd->flags bitmask array, informing downstream drivers that the early heap framework is fully initialized and operational.

The CONFIG_SYS_SPL_MALLOC_START identifier maps to an architecture-critical macro definition across embedded U-BOOT deployment pipelines, explicitly defining the physical baseline memory coordinates allocated to anchor the local heap context during the SPL phase. Because the physical memory available inside raw on-chip SRAM cells during the earliest stages of hardware bring-up is highly constrained, supporting dynamic memory allocation routines (the execution of standard malloc() loops) within the stripped SPL footprint requires that a precise, isolated region of volatile memory be manually fenced off to function as a temporary heap. This macro establishes the physical baseline boundary for that SPL heap allocation.

If an interrogation of the status bits inside gd->flags reveals that the GD_FLG_SPL_INIT indicator is unassigned, signifying that the foundational initialization routines targeting the SPL layer have not yet been processed, the state machine branches to call the core spl_init() function. This routine executes essential, mandatory low-level framework configurations. The linear software workflow mapping this initialization sequence is structured as follows:

Figure 5-25 spl_init() Function Flowchart

The bloblist_init() function checks for the existence of a binary blob list at the physical address defined by CONFIG_BLOBLIST_ADDR. If no valid list is detected, it initializes a new instance. The bloblist acts as a secure, centralized storage buffer to carry binary metadata structures across boot stages.

The setup_spl_handoff() routine checks this bloblist to verify if pre-staged handoff metadata exists. System engineers can populate custom handoff manifests via the struct spl_handoff structure to pass vital tracking data—such as high-level memory topology parameters, persistent reset status flags, and network controller MAC addresses—directly to the downstream operating system layers.

If the platform configuration enables board-level initialization hooks during the compilation step, developers can implement a custom spl_board_init() routine to execute platform-specific hardware provisioning before loading subsequent stages.

Furthermore, board_init_r() orchestrates the initialization of the hardware watchdog timer, configures the active DRAM bank parameters, and allocates a zero-initialized memory block to anchor the spl_image descriptor structure. The spl_image descriptor functions as the primary repository tracking the metadata required during the SPL boot pipeline. Its structural layout is defined as follows:

struct spl_image_info {	
const char *name;
	u8 os;
	uintptr_t load_addr;
	uintptr_t entry_point;
	void *fdt_addr;
	u32 boot_device;
	u32 size;
	u32 flags;
	void *arg;
	ulong dcrc_data;
	ulong dcrc_length;
	ulong dcrc;
	uint64_t rbindex;
};

The majority of these tracking fields are extracted directly from the image header block. The runtime argument field is bound by system parameters to .arg = CONFIG_SYS_SPL_ARG_ADDR, while the default storage device mapping is initialized to .boot_device = BOOT_DEVICE_NONE.

The board_boot_order() routine assigns the function pointer address of spl_boot_device() to the primary slot of the spl_boot_list array. This routing utility is declared with a weak linkage attribute, allowing developers to substitute a board-specific implementation. For the i.MX6 applications processor, the native spl_boot_device() routine reads the hardcoded state of the hardware boot mode registers to resolve and return the active primary storage device type.

Following this sequence, boot_from_devices() processes the prioritized order specified in the spl_boot_list. It scans the custom linker section .u_boot_list_2_spl_image_loader_1 to find a structural spl_image_loader entry that matches the active boot device. This linker-generated tracking structure encapsulates the peripheral type identifier, the descriptive device name string, the storage driver routine pointer (load_image), and the targeted program entry vector. Once a matching descriptor block is resolved, the system invokes spl_load_image(), which redirects execution straight into the storage-specific handler pointer load_image() to pull the U-BOOT Proper binary from physical storage blocks into RAM. If the load routine encounters a media fault or data verification error, it discards the tracking context and drops down to process the next sequential element inside the spl_boot_list, looping until a valid load succeeds or all registered peripherals are exhausted. The specialized section .u_boot_list_2_spl_image_loader_1 is generated statically at link time.

Upon successfully parsing and staging the target image file inside physical RAM, the state machine evaluates the operating system metadata field (os) inside the image header. It triggers a branch command to jump into the resolved entry vector using stage-specific handlers. For example, if the platform incorporates OP-TEE secure architectures (where the metadata flag maps to IH_OS_OPTEE), the system invokes spl_optee_entry() to surrender absolute platform execution to the secure runtime environment. Conversely, when the tracking parameter maps to IH_OS_LINUX, execution branches into the jump_to_image_linux() routine to pass absolute control over to the Linux bootstrap hooks.

To fetch and reconstruct binary files from physical media blocks, spl_load_image() relies directly on low-level media access operations provided by the peripheral subsystem drivers. For i.MX6 architectures booting from an MMC/SD interface controller, these media access routines are defined within the source module git/common/spl/spl_mmc.c, where the primary entry function is declared as spl_mmc_load_image.

The build system leverages the standard macro declaration SPL_LOAD_IMAGE_METHOD("MMC2", 0, BOOT_DEVICE_MMC2, spl_mmc_load_image) to bind the execution address of the spl_mmc_load_image routine straight to the primary load_image function pointer slot. If the platform configuration includes Device Tree capabilities, load_image() pulls the combined binary blob u-boot-dtb.imx from storage into RAM; if Device Tree support is disabled, it pulls the legacy container u-boot.imx. The subsequent sections analyze the operational stages through which the SPL layer unpacks and stages storage payloads, using spl_mmc_load_image() as a reference design model.

The true heavy lifting of fetching data blocks from physical media sectors is managed by the secondary helper routine spl_mmc_load(). The primary entry function spl_mmc_load_image() acts as an interface wrapper that evaluates active preprocessor build switches to pass distinct parameter configurations over to spl_mmc_load().

The spl_mmc_load() function initially checks if the targeted MMC/SD interface controller driver has completed its internal initialization. If the descriptor structure pointer evaluates to null, the routine calls spl_mmc_find_device() to resolve the platform-specific hardware controller index. Depending on whether the compiled U-BOOT binary implements the modern Driver Model (DM) architecture or relies on legacy driver frameworks, the code branches to invoke either mmc_init_device() or mmc_initialize() to fully bring up the storage interface. If the device descriptor is already active, the routine bypasses initialization entirely to execute immediate bus-level communication handshakes with the attached storage card.

It must be explicitly noted that if the core struct mmc descriptor block indicates that the target peripheral supports asynchronous initialization pipelines, mmc_init_device() invokes mmc_start_init() to launch the storage initialization routines as an asynchronous background thread, allowing the bootloader to proceed with non-dependent tasks simultaneously.

Upon completing the low-level hardware bring-up, spl_mmc_load() invokes mmc_init() to pull the raw Card Identification (CID) and Card-Specific Data (CSD) registers from the media, negotiating optimal operational clock frequencies and defining the maximum available data bus width (allocating 1-bit, 4-bit, or 8-bit lines).

Once bus negotiation succeeds, spl_mmc_load() calls spl_boot_mode() to poll the storage configuration parameters and isolate the specific data parsing layout supported by the medium. For an active MMC peripheral, the SPL runtime framework identifies exactly three primary boot modes: MMCSD_MODE_FS, MMCSD_MODE_EMMCBOOT, and MMCSD_MODE_RAW. The spl_boot_mode() utility is exported as a weak symbol, enabling system developers to override its evaluation rules via board-specific logic.

If the returned status forces an eMMC boot partition pathway (MMCSD_MODE_EMMCBOOT), the driver handles the hardware-specific partition switching loops required to target either the boot0 or boot1 hardware partition areas. If the active storage codebase is configured under a minimalist layout constraint (MMC_TINY), the driver maps a basic, direct register switch; otherwise, it invokes standard block device partition-selection routines.

When the state machine selects a raw sector block configuration (MMCSD_MODE_RAW), the parser prioritizes attempting a direct operating system launch. At this junction, if a call to the check routine spl_start_uboot() returns a logical false value, the SPL completely bypasses the secondary bootloader stage to load and launch the Linux kernel directly from raw blocks (known as Falcon Mode). Conversely, if spl_start_uboot() returns a logical true value, indicating that the platform must load the complete U-BOOT Proper binary image, the function evaluates the configuration parameters to read the full U-BOOT payload from either a distinct partition index (USE_PARTITION) or from an absolute, hardcoded sector offset address (USE_SECTOR).

If the platform is compiled to support multi-image redboot or redundant safe flashing infrastructures (CONFIG_DUAL_BOOTLOADER), the driver routes execution through spl_mmc_get_u_boot_raw_sector() to evaluate boundary conditions and isolate the precise starting sector offset hosting the primary U-BOOT image within the MMC layout.

If the parsed tracking parameters force a filesystem access profile (MMCSD_MODE_FS), the driver transfers execution control to the internal routine spl_mmc_do_fs_boot(). This block initiates low-level filesystem mounts to parse and traverse local FAT or EXT4 file allocation paths, searching for and extracting the primary bootloader file by its explicit filename mapping (such as searching for u-boot.img).

The technical flowchart provided below maps out the precise, end-to-end programmatic steps through which the spl_mmc_load_image() routine imports the U-BOOT Proper binary image from physical media into physical memory:

Figure 5-26 spl_mmc_load_image() Handoff Execution Flowchart

When the SPL is deployed to directly boot the guest operating system, it invokes the mmc_load_image_raw_os() function to copy the raw Linux kernel image blocks from the media sectors into physical memory. The execution pipeline tracking this raw operating system load routine is structured as follows:

Figure 5-27 mmc_load_image_raw_os() Function Flowchart

The following analysis profiles the operational workflow through which the SPL layer parses, loads, and extracts operating system components from modern multi-image structures, using the spl_load_simple_fit() routine as an architectural reference design model.

The spl_load_simple_fit() function accepts exactly four parameter arguments: a pointer to the target struct spl_image_info structure registering the runtime configuration metrics of the image, a pointer to a struct spl_load_info tracking layout defining the foundational parameters of the storage peripheral, a sector offset pointer designating the target block sequence to sample on the device, and a memory reference pointer targeting the source image file header. This routine parses the binary header blocks referenced by the file header pointer and populates the data fields inside the spl_image_info structure. As detailed in the preceding sections, this structure archives the vital metadata flags extracted from the image header to coordinate downstream image relocation and execution phases cleanly. The companion spl_load_info layout encapsulates low-level storage architecture parameters, declared as follows:

struct spl_load_info {
        void *dev;
        void *priv;
        int bl_len;
        const char *filename;
        ulong (*read)(struct spl_load_info *load, ulong sector, ulong count, void *buf);
};

Within this tracking layout, the .dev field points to the active boot storage peripheral device instance, .priv points to the private tracking structures managed by that specific peripheral, and .bl_len registers the device's native data access block boundary size (block length in bytes). The .read field maps to a localized block-read function pointer provided directly by the underlying storage peripheral's device driver module.

The spl_load_simple_fit() routine initially determines the absolute size of the target .itb container file, calculates the memory constraints required to accommodate the payload, and calls the driver-specific function pointer .read to read the entire FIT image block stream from storage into an isolated scratch buffer memory. Once the image metadata blocks are staged inside this memory cache, the internal parser executes a structural traversal across the image tree to isolate the core /images container node.

Upon successfully resolving the /images tree node, if the platform compilation profile includes dual-boot rollback protection capabilities, the parsing engine queries the /configurations container block to look up the secure rollback index (rbindex) attribute. If a valid rbindex marker is found, its relative structural byte offset address within the image file is calculated and written directly into the .rbindex domain tracking field inside the spl_image_info structure.

Concurrently, if the platform configuration includes integrated FPGA subsystem support, spl_load_simple_fit() evaluates the /images tree branches to isolate any embedded /fpga child nodes; if an active bitstream segment is found, the routine calls downstream programming paths to write that binary image directly into the physical FPGA configuration registers.

If FPGA support is disabled or the active .itb container file lacks an integrated /fpga node, the parser scans the active target /configurations node to extract the default software stack parameters. It initially attempts to resolve a /firmware assignment property; if that field is missing, it drops down to parse the primary /kernel assignment entry, and if that lookup also fails, it searches for a secondary generic /loadable allocation property. If the tree parser completes this cascade without resolving any valid bootable components, the function returns a failure error code. Conversely, if a target configuration node is resolved, the system routes execution control to the internal routine spl_load_fit_image(). This helper function validates and relocates the matching image files into their physical destination memory targets (or maps their relative coordinates if the binary blocks are already present in RAM) and executes the targeted data decompression algorithms. The sequential software execution pipeline tracking this workflow is structured as follows:

Figure 5-28 spl_load_simple_fit() Function Flowchart

For a standard Linux compilation target, once the core kernel image payloads have been successfully staged and unpacked within physical memory, the jump_to_image_linux() routine interrogates the entry point metadata domain (entry) declared within the image header to establish the absolute starting instruction address of the kernel. It then executes essential runtime environment cleanup loops, silhouettes the asynchronous clock engines, and turns off internal caches.

At the absolute termination cycle, it calls the execution entry wrapper image_entry(), passing the registered target machine identifier code (machid) and the boot argument vector reference pointer (spl_image->arg) directly over to the guest operating system while forcing a hardware execution branch to jump straight into the resolved kernel entry address. At this exact instruction loop, the SPL layer completes its lifecycle, and the newly active Linux kernel takes full control of the entire hardware platform.

This concludes Chapter 5 and the exhaustive technical analysis tracking the U-BOOT Bootloader and Embedded SPL Initialization Lifecycles.

Copyright © 2026 Guangzhou eSmart Information Technology Co., Ltd. All Rights Reserved.
All content in this book is copyrighted by the author. For personal learning and exchange only. Commercial use without authorization is strictly prohibited. Email:

✉ 3348194517@qq.com | hai616878@gmail.com